package com.xu.crawler.core;

import com.google.common.collect.Lists;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import us.codecraft.webmagic.Spider;
import us.codecraft.webmagic.downloader.Downloader;
import us.codecraft.webmagic.downloader.HttpClientDownloader;
import us.codecraft.webmagic.processor.PageProcessor;
import us.codecraft.webmagic.proxy.Proxy;
import us.codecraft.webmagic.proxy.SimpleProxyProvider;

import javax.annotation.Resource;

/**
 * Created by clear on 2018/8/19.
 */
//@Component
//public class MySpider extends Spider {
//    private static Downloader downloader = new HttpClientDownloader();
//    @Resource
//    private MongoTemplate mongoTemplate;
//
//    @Scheduled(cron = "0 */5 * * * ?")
//    private void refreshProxy() {
//
//    }
//
//    public MySpider(PageProcessor pageProcessor) {
//        super(pageProcessor);
//        this.site = pageProcessor.getSite();
//    }
//
//    public static MySpider create(PageProcessor pageProcessor) {
//        MySpider mySpider = new MySpider(pageProcessor);
//        downloader.setProxyProvider(new SimpleProxyProvider(
//                Lists.newArrayList(new Proxy("116.62.194.248", 3128))
//        ));
//        mySpider.setDownloader(downloader);
//        return mySpider;
//    }
//
//}